<?php

function rpc( $json_request ) {
    global $PARAPARA;

    $req_param = $json_request->param;

    if(!$req_param) {
        return new RPC_Error($json_request->operation, "PARAM", "No params");
    };

    $dbl = $PARAPARA->dblayer;

    $since_id = $req_param->since;

    if(!isset($since_id) || !is_numeric( $since_id ) )
        $since_id = 0;


    $messages = $dbl->get_chat_messages( $since_id );
    $chat     = new Chat( $messages );

    $rpc_retval = 
        array( 'html'        => $chat->as_html( null ),
               'shout_count' => $chat->shout_count,
               'newest_id'   => $chat->newest_id
        );

    return new RPC_Response( $json_request->operation, $rpc_retval );

}

return rpc( $json_request );

?>